package com.admin.business.workManagement.venusOaWorkApproval;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 工作安排审批表
 * @create: 2023-11-14 15:21:40
 **/
@Service("venusOaWorkApprovalService")
@Slf4j
public class VenusOaWorkApprovalService{

    @Resource
    VenusOaWorkApprovalDao venusOaWorkApprovalDao;

    /**
     * 添加工作安排审批表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - work_id:工作安排id
     *                   - approval_state:审批状态(0.正常1.同意2.拒绝)
     *                   - approval_person:审批人id
     *                   - approval_time:审批时间
     *                   - approval_updatetime_agree_starttime:修改时间审批同意修改任务时间(开始)
     *                   - approval_updatetime_agree_endtime:修改时间审批同意修改任务时间(结束)
     *                   - approval_updatetime_agree_reason:修改时间审批同意原因
     *                   - approval_updatetime_refuse_reason:修改时间审批拒绝原因
     *                   - approval_refuse_agree_reason:拒绝工作安排同意原因
     *                   - approval_refuse_refuse_reason:拒绝工作安排拒绝原因
     *                   - approval_refuse_reass_starttime:改派重设工作时间(开始)
     *                   - approval_refuse_reass_endtime:改派重设工作时间(结束)
     *                   - approval_chooseperson_dept_id:改派 工作人员部门id
     *                   - approval_chooseperson_post_id:改派 工作人员岗位id
     *                   - approval_chooseperson_employee_id:改派 工作人员员工id
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return addVenusOaWorkApproval(CDO cdoRequest) {
        venusOaWorkApprovalDao.addVenusOaWorkApproval(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新工作安排审批表数据
     *
     * @param cdoRequest - id:主键
     *                   - work_id:工作安排id
     *                   - approval_state:审批状态(0.正常1.同意2.拒绝)
     *                   - approval_person:审批人id
     *                   - approval_time:审批时间
     *                   - approval_updatetime_agree_starttime:修改时间审批同意修改任务时间(开始)
     *                   - approval_updatetime_agree_endtime:修改时间审批同意修改任务时间(结束)
     *                   - approval_updatetime_agree_reason:修改时间审批同意原因
     *                   - approval_updatetime_refuse_reason:修改时间审批拒绝原因
     *                   - approval_refuse_agree_reason:拒绝工作安排同意原因
     *                   - approval_refuse_refuse_reason:拒绝工作安排拒绝原因
     *                   - approval_refuse_reass_starttime:改派重设工作时间(开始)
     *                   - approval_refuse_reass_endtime:改派重设工作时间(结束)
     *                   - approval_chooseperson_dept_id:改派 工作人员部门id
     *                   - approval_chooseperson_post_id:改派 工作人员岗位id
     *                   - approval_chooseperson_employee_id:改派 工作人员员工id
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return updateVenusOaWorkApprovalById(CDO cdoRequest) {
        venusOaWorkApprovalDao.updateVenusOaWorkApprovalById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除工作安排审批表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return deleteVenusOaWorkApprovalById(CDO cdoRequest){
        int count = venusOaWorkApprovalDao.deleteVenusOaWorkApprovalById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除工作安排审批表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return deleteVenusOaWorkApproval(CDO cdoRequest) {
        int count = venusOaWorkApprovalDao.deleteVenusOaWorkApproval(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取工作安排审批表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkApprovalById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaWorkApprovalDao.getVenusOaWorkApprovalById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取工作安排审批表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkApprovalListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkApprovalDao.getVenusOaWorkApprovalListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkApprovalDao.getVenusOaWorkApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取工作安排审批表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-14 15:21:40
     */
    @OpenApi
    public Return getVenusOaWorkApprovalListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaWorkApprovalDao.getVenusOaWorkApprovalListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaWorkApprovalDao.getVenusOaWorkApprovalCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
